package ua.lviv.franko.solvers.stressanalysis.twoDimention;

import java.util.List;

import ua.lviv.franko.integration.FunctionWithoutDerivatives2D;
import ua.lviv.franko.integration.IFunction2D;
import ua.lviv.franko.solvers.stressanalysis.twoDimention.fem.AbstractStressElement;

public class FEMResultStress {
	private double[]					results;
	private List<AbstractStressElement>	elements;

	public FEMResultStress(double[] results, List<AbstractStressElement> elements) {
		super();
		this.results = results;
		this.elements = elements;
	}

	public IFunction2D getU() {
		return new FunctionWithoutDerivatives2D() {

			@Override
			public double calculate(double x, double y) {
				double val = 0.0;
				int i = 0;
				while (val == 0.0 && i < elements.size()) {
					val += elements.get(i).calculateU(x, y, results);
					i++;
				}
				return val;
			}
		};
	}
	
	public IFunction2D getV() {
		return new FunctionWithoutDerivatives2D() {

			@Override
			public double calculate(double x, double y) {
				double val = 0.0;
				int i = 0;
				while (val == 0.0 && i < elements.size()) {
					val += elements.get(i).calculateV(x, y, results);
					i++;
				}
				return val;
			}
		};
	}
	
	public IFunction2D getSigma11() {
		return new FunctionWithoutDerivatives2D() {

			@Override
			public double calculate(double x, double y) {
				double val = 0.0;
				int i = 0;
				while (val == 0.0 && i < elements.size()) {
					val += elements.get(i).calculateSigma11(x, y, results);
					i++;
				}
				return val;
			}
		};
	}
	
	public IFunction2D getSigma12() {
		return new FunctionWithoutDerivatives2D() {

			@Override
			public double calculate(double x, double y) {
				double val = 0.0;
				int i = 0;
				while (val == 0.0 && i < elements.size()) {
					val += elements.get(i).calculateSigma12(x, y, results);
					i++;
				}
				return val;
			}
		};
	}
	
	public IFunction2D getSigma22() {
		return new FunctionWithoutDerivatives2D() {

			@Override
			public double calculate(double x, double y) {
				double val = 0.0;
				int i = 0;
				while (val == 0.0 && i < elements.size()) {
					val += elements.get(i).calculateSigma22(x, y, results);
					i++;
				}
				return val;
			}
		};
	}

}
